package com.ruoyi.web.controller.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysWzxUser;
import com.ruoyi.web.controller.mapper.SysSchedulPaiMapper;
import com.ruoyi.web.controller.demo.domain.SysSchedulPai;
import com.ruoyi.web.controller.service.ISysSchedulPaiService;
import com.ruoyi.common.core.text.Convert;

/**
 * sys_schedul_paiService业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-27
 */
@Service
public class SysSchedulPaiServiceImpl implements ISysSchedulPaiService 
{
    @Autowired
    private SysSchedulPaiMapper sysSchedulPaiMapper;

    /**
     * 查询sys_schedul_pai
     * 
     * @param id sys_schedul_pai主键
     * @return sys_schedul_pai
     */
    @Override
    public SysSchedulPai selectSysSchedulPaiById(Long id)
    {
        return sysSchedulPaiMapper.selectSysSchedulPaiById(id);
    }

    /**
     * 查询sys_schedul_pai列表
     * 
     * @param sysSchedulPai sys_schedul_pai
     * @return sys_schedul_pai
     */
    @Override
    public List<SysSchedulPai> selectSysSchedulPaiList(SysSchedulPai sysSchedulPai)
    {
        return sysSchedulPaiMapper.selectSysSchedulPaiList(sysSchedulPai);
    }

    /**
     * 新增sys_schedul_pai
     * 
     * @param sysSchedulPai sys_schedul_pai
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysSchedulPai(SysSchedulPai sysSchedulPai)
    {
        sysSchedulPai.setCreateTime(DateUtils.getNowDate());
        int rows = sysSchedulPaiMapper.insertSysSchedulPai(sysSchedulPai);
        insertSysWzxUser(sysSchedulPai);
        return rows;
    }

    /**
     * 修改sys_schedul_pai
     * 
     * @param sysSchedulPai sys_schedul_pai
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysSchedulPai(SysSchedulPai sysSchedulPai)
    {
//        sysSchedulPaiMapper.deleteSysWzxUserByUserId(sysSchedulPai.getId());
        insertSysWzxUser(sysSchedulPai);
        return sysSchedulPaiMapper.updateSysSchedulPai(sysSchedulPai);
    }

    /**
     * 批量删除sys_schedul_pai
     * 
     * @param ids 需要删除的sys_schedul_pai主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysSchedulPaiByIds(String ids)
    {
//        sysSchedulPaiMapper.deleteSysWzxUserByUserIds(Convert.toStrArray(ids));
        return sysSchedulPaiMapper.deleteSysSchedulPaiByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除sys_schedul_pai信息
     * 
     * @param id sys_schedul_pai主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysSchedulPaiById(Long id)
    {
//        sysSchedulPaiMapper.deleteSysWzxUserByUserId(id);
        return sysSchedulPaiMapper.deleteSysSchedulPaiById(id);
    }

    /**
     * 新增人员信息信息
     * 
     * @param sysSchedulPai sys_schedul_pai对象
     */
    public void insertSysWzxUser(SysSchedulPai sysSchedulPai)
    {
        List<SysWzxUser> sysWzxUserList = sysSchedulPai.getSysWzxUserList();
        Long id = sysSchedulPai.getId();
        if (StringUtils.isNotNull(sysWzxUserList))
        {
            List<SysWzxUser> list = new ArrayList<SysWzxUser>();
            for (SysWzxUser sysWzxUser : sysWzxUserList)
            {
                sysWzxUser.setUserId(id);
                list.add(sysWzxUser);
            }
            if (list.size() > 0)
            {
                sysSchedulPaiMapper.batchSysWzxUser(list);
            }
        }
    }
}
